home *** CD-ROM | disk | FTP | other *** search
- /*
- * JPEG Convert3.c
- *
- * Copyright (C) 1992, James H. Brunner.
- *
- * This file is part of the "JPEG Convert" program. The JPEG Convert program signature ('Ijgp')
- * and unique file types ('TARG', 'RLE ', 'PPM ') are registered with Apple by the author.
- *
- * The JPEG Convert program is an image format conversion program that utilizes the software of
- * the Independent JPEG Group. The JPEG Convert program is essentially a Macintosh user interface
- * around the Independent JPEG Group's code. The author of JPEG Convert maintains a copyright to
- * the interface software only. For conditions of distribution and use of the Independent JPEG
- * Group's software, refer to the README file contained in the Independent JPEG Group's distribution
- * package.
- *
- * (Further use of the word 'software' refers only to the source files for implementing this user
- * interface, including the resource file which does not include this comment. It does NOT refer
- * to the Independent JPEG Group's code.)
- *
- * The conditions for distribution of this software are as follows:
- * This software may be freely distributed provided that it is not distributed for profit; a
- * nominal copying fee may be charged.
- *
- * Any distribution of this software must contain all original copyright notices.
- *
- * The conditions for use of this software IN FULL are as follows:
- * This software may be used in full by any person or business provided that the person or
- * business is not seeking profits directly from the use of this software.
- *
- * The conditions for use of this software IN PART are as follows:
- * Any person or business may copy and utilize portions of this software in other products
- * provided that a note that "portions of the software are copyright by James H. Brunner"
- * is included in the software AND the resultant software is not intended to be distributed
- * for profit.
- *
- * If SOURCE for projects containing portions of this code is not to be made available
- * with the resultant programs, an additional note that "portions of the software are
- * copyright James H. Brunner" must be included in some visable user documentation.
- *
- * Bottom line: I give it away free; I don't want you selling it. You can use the source if
- * you wish, but don't sell it. If you use my work, give me credit for it.
- */
-
- /*
- * JPEG Convert3.c
- *
- * This is part 3 of the Macintosh GUI (Graphical User Interface). It is intended to be
- * compiled on a Macintosh computer with Think C. This file contains the about box and
- * help. "JPEG Convert1.c" and "JPEG Convert2.c" contain the rest.
- */
-
-
- #include "JPEG Convert.h"
-
- #define ABOUT_DLOG 129
- #define ABOUT_TEXT 128
- #define ABOUT_CREDIT 129
-
- #define WF_PICT 128
- #define JIM_BW 129
- #define TAM_BW 130
- #define JIM_16 131
- #define TAM_16 132
-
- #define CREDIT_OFFSET 60
-
- enum {
- kAboutCredit=2,
- kAboutScroll,
- kAboutText,
- kAboutOKBorder,
- kJimPic,
- kTamPic
- };
-
- extern Boolean gNewDialogMgr; /* EXTERN: TRUE if the system 7 dialog manager is available */
- extern Boolean gAppleEvents; /* EXTERN: TRUE if the system 7 apple event facility is available */
- extern Boolean gColorQuickdraw; /* EXTERN: TRUE if color qd and main screen > 4 colors */
- extern Boolean gFSSpecSupport; /* EXTERN: TRUE if machine supports FSSpecs */
-
- static Handle gHandleSink;
- static TEHandle gHelpText;
- static int gHelpLine; /* (1 based) */
-
-
- METHODDEF pascal void
- AboutTextItem (WindowPtr d, short dinum)
- {
- short itemType;
- Rect textRect;
-
- GetDItem(d, kAboutText, &itemType, &gHandleSink, &textRect);
- PenSize(1,1);
- FrameRect(&textRect);
-
- if (gHelpText != NULL) {
- InsetRect(&textRect, 4, 2);
- TEUpdate(&textRect, gHelpText);
- } else {
- PicHandle picHand;
- int picHeight, picWidth;
-
- picHand = (PicHandle)GetResource('PICT', WF_PICT);
- picHeight = (**picHand).picFrame.bottom - (**picHand).picFrame.top;
- picWidth = (**picHand).picFrame.right - (**picHand).picFrame.left;
- textRect.left = (textRect.left + textRect.right - picWidth) / 2;
- textRect.top = (textRect.top + textRect.bottom - picHeight) / 2;
- textRect.right = textRect.left + picWidth;
- textRect.bottom = textRect.top + picHeight;
- DrawPicture(picHand, &textRect);
- }
- }
-
-
- METHODDEF pascal void
- PicItem (WindowPtr d, short dinum)
- {
- short itemType;
- Rect itemr;
- PicHandle picHand;
-
- if (gColorQuickdraw)
- if (dinum == kJimPic)
- picHand = (PicHandle)GetResource('PICT', JIM_16);
- else
- picHand = (PicHandle)GetResource('PICT', TAM_16);
- else
- if (dinum == kJimPic)
- picHand = (PicHandle)GetResource('PICT', JIM_BW);
- else
- picHand = (PicHandle)GetResource('PICT', TAM_BW);
-
- GetDItem(d, dinum, &itemType, &gHandleSink, &itemr);
- itemr.right = itemr.left + ((**picHand).picFrame.right - (**picHand).picFrame.left);
- itemr.bottom = itemr.top + ((**picHand).picFrame.bottom - (**picHand).picFrame.top);
-
- DrawPicture(picHand, &itemr);
-
- ReleaseResource((Handle)picHand);
- }
-
-
- METHODDEF pascal void
- AboutScrollBar (ControlHandle theControl, short thePart)
- {
- short currentVal;
- short maxVal;
- int linesToScroll;
- int totalHeight;
- int windHeight;
-
- currentVal = GetCtlValue(theControl);
- maxVal = GetCtlMax(theControl);
- switch (thePart) {
- case inUpButton:
- if (gHelpLine > 1) {
- gHelpLine--;
- TEScroll(0, TEGetHeight(gHelpLine, gHelpLine, gHelpText), gHelpText);
- }
- break;
- case inDownButton:
- if (gHelpLine < maxVal) {
- TEScroll(0, -TEGetHeight(gHelpLine, gHelpLine, gHelpText), gHelpText);
- gHelpLine++;
- }
- break;
- case inPageUp:
- windHeight = (**gHelpText).viewRect.bottom - (**gHelpText).viewRect.top;
- windHeight -= TEGetHeight(gHelpLine, gHelpLine, gHelpText);
- totalHeight = 0;
- linesToScroll = 0;
- while ((totalHeight <= windHeight) && (gHelpLine - (linesToScroll-1) > 0)) {
- linesToScroll++;
- totalHeight += TEGetHeight(gHelpLine-linesToScroll, gHelpLine-linesToScroll, gHelpText);
- }
- linesToScroll -= 1; /* Ignore partial line */
- TEScroll(0, TEGetHeight(gHelpLine-linesToScroll, gHelpLine-1, gHelpText), gHelpText);
- gHelpLine -= linesToScroll;
- break;
- case inPageDown:
- windHeight = (**gHelpText).viewRect.bottom - (**gHelpText).viewRect.top;
- totalHeight = 0;
- linesToScroll = 0;
- while ((totalHeight <= windHeight) && (gHelpLine + linesToScroll-2 < maxVal)) {
- totalHeight += TEGetHeight(gHelpLine+linesToScroll, gHelpLine+linesToScroll, gHelpText);
- linesToScroll++;
- }
- linesToScroll -= 2; /* Keep one line, ignore partial line */
- TEScroll(0, -TEGetHeight(gHelpLine, gHelpLine+linesToScroll-1, gHelpText), gHelpText);
- gHelpLine += linesToScroll;
- break;
- }
-
- SetCtlValue(theControl, gHelpLine);
- }
-
-
- METHODDEF pascal Boolean
- about_dialog_filter (DialogPtr d, EventRecord *theEvent, short *item)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- Point mouseLoc;
- short thePart;
- char theKey;
- Boolean command;
- Boolean alreadyHandled=FALSE;
- ControlHandle theControl;
-
- SetPort(d);
-
- if (ReturnEnterEscape(d, theEvent, item))
- return TRUE;
-
- switch (theEvent->what) {
- case mouseDown:
- mouseLoc = (theEvent->where);
- GlobalToLocal(&mouseLoc);
-
- GetDItem(d, kAboutScroll, &itemType, &itemHandle, &itemRect);
- if (PtInRect(mouseLoc, &itemRect)) {
-
- thePart = FindControl(mouseLoc, d, &theControl);
- /* if the hit was in an arrow or page area, we'll handle it */
- if (thePart != inThumb) {
- TrackControl(theControl, mouseLoc, (ProcPtr)AboutScrollBar);
- alreadyHandled = TRUE;
- }
- }
- break;
- }
-
- /* If we have already handled the event, pass back a nullEvent to keep ModalDialog from
- * returning. Otherwise, if we are using the NEW dialog manager, we need to call the
- * standard filter proc.
- */
- if (alreadyHandled) {
- theEvent->what = nullEvent;
- return FALSE; /* tricks the dialog manager into handling a null event */
- }
-
- if (gNewDialogMgr) {
- ModalFilterProcPtr theModalProc;
-
- if (GetStdFilterProc(&theModalProc) == noErr)
- return theModalProc(d, theEvent, item);
- }
-
- return FALSE;
- }
-
-
- GLOBAL void
- DoAboutBox ()
- {
- WindowPtr AboutBox;
- Rect textRect;
- short item;
- Rect itemr;
- short itemType;
- Handle hTEXT;
- StScrpHandle hstyl;
- int windHeight;
- int totalHeight;
- int lastPageLines;
- int newLine;
- Boolean creditMode=FALSE;
-
- if (gAppleEvents)
- if (AEInteractWithUser(kAEDefaultTimeout, NULL, NULL)) {
- SysBeep(0L);
- return;
- }
-
- gHelpText = NULL;
-
- if (!gNewDialogMgr)
- CenterDialog(ABOUT_DLOG, NULL);
- AboutBox = GetNewDialog(ABOUT_DLOG, NULL, (WindowPtr)-1);
- SetPort(AboutBox);
-
- /* If we are using the NEW dialog manager, it will handle the OK and CANCEL keyboard
- * equivalents. It will also border the OK button for us. We don't wan't it to
- * track the cursor since we have a "disabled" editText item.
- */
- if (gNewDialogMgr) {
- SetDialogDefaultItem(AboutBox, ok);
- SetDialogCancelItem(AboutBox, ok);
-
- GetDItem(AboutBox, kAboutOKBorder, &item, &gHandleSink, &itemr);
- SetDItem(AboutBox, kAboutOKBorder, item, (Handle)NOPRoutine, &itemr);
- } else {
- GetDItem(AboutBox, kAboutOKBorder, &item, &gHandleSink, &itemr);
- SetDItem(AboutBox, kAboutOKBorder, item, (Handle)BorderDefault, &itemr);
- }
-
- GetDItem(AboutBox, kAboutText, &item, &gHandleSink, &textRect);
- SetDItem(AboutBox, kAboutText, item, (Handle)AboutTextItem, &textRect);
-
- HideDItem(AboutBox, kJimPic);
- HideDItem(AboutBox, kTamPic);
-
- ShowWindow(AboutBox);
- DrawDialog(AboutBox);
-
- InsetRect(&textRect, 4, 2);
- gHelpText = TEStylNew(&textRect, &textRect);
- gHelpLine = 1;
-
- hTEXT = GetResource('TEXT', ABOUT_TEXT);
- hstyl = (StScrpHandle)GetResource('styl', ABOUT_TEXT);
-
- HLock(hTEXT);
- TEStylInsert(*hTEXT, SizeResource(hTEXT), hstyl, gHelpText);
- HUnlock(hTEXT);
-
- ReleaseResource(hTEXT);
- ReleaseResource((Handle)hstyl);
-
- windHeight = (**gHelpText).viewRect.bottom - (**gHelpText).viewRect.top;
- totalHeight = 0;
- lastPageLines = 0;
- while (totalHeight <= windHeight) {
- totalHeight += TEGetHeight((**gHelpText).nLines-lastPageLines, (**gHelpText).nLines-lastPageLines, gHelpText);
- lastPageLines++;
- }
- lastPageLines -= 1; /* Ignore partial line */
-
- SetCtlMax(CITEMH(AboutBox, kAboutScroll), (**gHelpText).nLines-(lastPageLines-1));
-
- GetDItem(AboutBox, kJimPic, &item, &gHandleSink, &itemr);
- SetDItem(AboutBox, kJimPic, item, (Handle)PicItem, &itemr);
- GetDItem(AboutBox, kTamPic, &item, &gHandleSink, &itemr);
- SetDItem(AboutBox, kTamPic, item, (Handle)PicItem, &itemr);
-
- BeginUpdate(AboutBox);
- EndUpdate(AboutBox);
- GetDItem(AboutBox, kAboutOKBorder, &item, &gHandleSink, &itemr);
- InvalRect(&itemr);
-
- for (;;) {
- ModalDialog(about_dialog_filter, &item);
- if (item == ok)
- break;
-
- switch (item) {
- case kAboutCredit:
- TEDispose(gHelpText);
- gHelpText = NULL;
-
- if (creditMode) {
- HideDItem(AboutBox, kJimPic);
- HideDItem(AboutBox, kTamPic);
- GetDItem(AboutBox, kAboutText, &item, &gHandleSink, &textRect);
- EraseRect(&textRect);
- textRect.left -= CREDIT_OFFSET;
- SetDItem(AboutBox, kAboutText, item, (Handle)AboutTextItem, &textRect);
-
- SetCTitle(CITEMH(AboutBox, kAboutCredit), "\pCredits...");
-
- AboutTextItem(AboutBox, kAboutText);
-
- InsetRect(&textRect, 4, 2);
- gHelpText = TEStylNew(&textRect, &textRect);
- gHelpLine = 1;
-
- hTEXT = GetResource('TEXT', ABOUT_TEXT);
- hstyl = (StScrpHandle)GetResource('styl', ABOUT_TEXT);
- } else {
- ShowDItem(AboutBox, kJimPic);
- ShowDItem(AboutBox, kTamPic);
- GetDItem(AboutBox, kAboutText, &item, &gHandleSink, &textRect);
- EraseRect(&textRect);
- textRect.left += CREDIT_OFFSET;
- SetDItem(AboutBox, kAboutText, item, (Handle)AboutTextItem, &textRect);
-
- SetCTitle(CITEMH(AboutBox, kAboutCredit), "\pHelp...");
-
- AboutTextItem(AboutBox, kAboutText);
- PicItem(AboutBox, kJimPic);
- PicItem(AboutBox, kTamPic);
-
- InsetRect(&textRect, 4, 2);
- gHelpText = TEStylNew(&textRect, &textRect);
- gHelpLine = 1;
-
- hTEXT = GetResource('TEXT', ABOUT_CREDIT);
- hstyl = (StScrpHandle)GetResource('styl', ABOUT_CREDIT);
- }
-
- HLock(hTEXT);
- TEStylInsert(*hTEXT, SizeResource(hTEXT), hstyl, gHelpText);
- HUnlock(hTEXT);
-
- ReleaseResource(hTEXT);
- ReleaseResource((Handle)hstyl);
-
- windHeight = (**gHelpText).viewRect.bottom - (**gHelpText).viewRect.top;
- totalHeight = 0;
- lastPageLines = 0;
- while (totalHeight <= windHeight) {
- totalHeight += TEGetHeight((**gHelpText).nLines-lastPageLines, (**gHelpText).nLines-lastPageLines, gHelpText);
- lastPageLines++;
- }
- lastPageLines -= 1; /* Ignore partial line */
-
- SetCtlMax(CITEMH(AboutBox, kAboutScroll), (**gHelpText).nLines-(lastPageLines-1));
- SetCtlValue(CITEMH(AboutBox, kAboutScroll), gHelpLine);
-
- BeginUpdate(AboutBox); /* We've done all of the necessary updating */
- EndUpdate(AboutBox); /* this will eliminate flicker */
- GetDItem(AboutBox, kAboutOKBorder, &item, &gHandleSink, &itemr);
- InvalRect(&itemr);
-
- creditMode = !creditMode;
- break;
-
- case kAboutScroll:
- /* take care of the thumb */
- newLine = GetCtlValue(CITEMH(AboutBox, kAboutScroll));
- if (newLine > gHelpLine)
- TEScroll(0, -TEGetHeight(gHelpLine, newLine-1, gHelpText), gHelpText);
- else
- TEScroll(0, TEGetHeight(gHelpLine-1, newLine, gHelpText), gHelpText);
- gHelpLine = newLine;
- break;
- }
- }
-
- DisposDialog(AboutBox);
- InitCursor();
- TEDispose(gHelpText);
- gHelpText = NULL;
- }
-
-
- GLOBAL OSErr
- xFSMakeFSSpec (
- short vRefNum,
- long dirID,
- ConstStr255Param fileName,
- FSSpecPtr spec)
- {
- OSErr err;
-
- if (gFSSpecSupport)
- err = FSMakeFSSpec(vRefNum, dirID, fileName, spec);
- else {
- Str255 tempName;
- CInfoPBRec pb;
-
- COPY(tempName, fileName);
-
- pb.hFileInfo.ioCompletion = nil;
- pb.hFileInfo.ioNamePtr = tempName;
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioFDirIndex = 0;
- pb.hFileInfo.ioDirID = dirID;
- err = PBGetCatInfo(&pb, FALSE);
-
- spec->vRefNum = vRefNum;
- spec->parID = dirID;
- COPY(spec->name, pb.hFileInfo.ioNamePtr);
- }
- return err;
- }
-
-
- GLOBAL OSErr
- xFSpCreateResFile (
- const FSSpec *spec,
- OSType creator,
- OSType fileType,
- ScriptCode scriptTag)
- {
- OSErr err;
-
- if (gFSSpecSupport) {
- FSpCreateResFile(spec, creator, fileType, scriptTag);
- err = ResError();
- } else {
- HParamBlockRec pb;
- Str255 tempName;
-
- FSSpecToName(*spec, tempName);
- CreateResFile(tempName);
- err = ResError();
-
- if (err == noErr) {
- pb.fileParam.ioCompletion = nil;
- pb.fileParam.ioNamePtr = (unsigned char *)spec->name;
- pb.fileParam.ioVRefNum = spec->vRefNum;
- pb.fileParam.ioDirID = spec->parID;
- pb.fileParam.ioFDirIndex = 0;
- err = PBHGetFInfo(&pb, FALSE);
- if (err == noErr) {
- pb.fileParam.ioDirID = spec->parID;
- pb.fileParam.ioFlFndrInfo.fdType = fileType;
- pb.fileParam.ioFlFndrInfo.fdCreator = creator;
- err = PBHSetFInfo(&pb, FALSE);
- }
- }
- }
- return err;
- }
-
-
- GLOBAL short
- xFSpOpenResFile (
- const FSSpec *spec,
- SignedByte permission)
- {
- short refNum;
-
- if (gFSSpecSupport) {
- refNum = FSpOpenResFile(spec, permission);
- } else {
- Str255 tempName;
-
- FSSpecToName(*spec, tempName);
- refNum = OpenRFPerm(tempName, spec->vRefNum, permission);
- }
- return refNum;
- }
-